package api

import (
	"github.com/gin-gonic/gin"
	"zsc-boot/app/customer/model"
	"zsc-boot/app/customer/service"
	"zsc-boot/core"
	"zsc-boot/core/web"
)

type OrderAddApi struct {
	svc *service.OrderAddSvc
}

func NewOrderAddApi() *OrderAddApi {
	return &OrderAddApi{svc: new(service.OrderAddSvc)}
}

// Update 修改
func (o *OrderAddApi) Update(ctx *gin.Context) {
	var req model.OrderAdd
	_ = ctx.Bind(&req)
	if err := o.svc.Update(req); err != nil {
		web.FailResponse(ctx, err, err.Error())
		return
	} else {
		web.SuccessResponse(ctx, nil)
	}
}

// Create 创建
func (o *OrderAddApi) Create(ctx *gin.Context) {
	var req model.OrderAdd
	_ = ctx.Bind(&req)
	if err := o.svc.Create(req); err != nil {
		web.FailResponse(ctx, err, err.Error())
		return
	} else {
		web.SuccessResponse(ctx, nil)
	}
}

// Delete 删除
func (o *OrderAddApi) Delete(ctx *gin.Context) {
	var req core.GetById
	_ = ctx.Bind(&req)
	if err := o.svc.Delete(req.ID); err != nil {
		web.FailResponse(ctx, err, err.Error())
		return
	} else {
		web.SuccessResponse(ctx, nil)
	}
}
